package com.credithc.customers.base.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.credithc.baseserv.core.utils.UUIDUtils;
import com.credithc.customers.base.codes.CustomerCodes;
import com.credithc.customers.base.configure.PropertiesConfig;
import com.credithc.customers.base.constants.CustomerConstants;
import com.credithc.customers.base.constants.TableEnum;
import com.credithc.customers.base.exception.CustomerException;
import com.credithc.customers.base.factory.DictionaryFactory;
import com.credithc.customers.base.mapper.*;
import com.credithc.customers.base.po.*;
import com.credithc.customers.base.ro.*;
import com.credithc.customers.base.service.ICommonService;
import com.credithc.customers.base.utils.*;
import com.credithc.customers.base.vo.CustOauthTokenVo;
import com.credithc.customers.base.vo.LoginFlowVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.X509EncodedKeySpec;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhukai
 * @date 2018/12/20 13:47
 */
@Service
@Slf4j
public class CommonServiceImpl implements ICommonService {

    private final PreCustomerMapper preCustomerMapper;

    private final CustomerContactInfoMapper customerContactInfoMapper;

    private final CustomerMapper customerMapper;

    private final CustomerIdInfoMapper customerIdInfoMapper;

    private final CustomMapper customMapper;

    private final CustomerExtendMapper customerExtendMapper;

    private final SystemInfoMapper systemInfoMapper;

    private final CustomerRelationInfoMapper relationMapper;

    private final ProductInfoMapper productMapper;

    private final CustomerProductMapper customerProductMapper;

    private final CustomerAccountMapper customerAccountMapper;

    private final DictMapperMapper dictMapperMapper;

    private final CustomerRoleMapper customerRoleMapper;

    private final NoticeLogMapper noticeLogMapper;

    private final CustomerContactFlowMapper contactFlowMapper;

    private final CompanyIdInfoMapper companyIdInfoMapper;

    private final CustomerManageInfoMapper customerManageInfoMapper;

    private final PreCustomerPassMapper preCustomerPassMapper;

    private final PreCustomerUnifyRegisterMapper preCustomerUnifyRegisterMapper;

    private final UnifySmsMapper unifySmsMapper;

    private final PreCustomerUnifyLoginMapper preCustomerUnifyLoginMapper;

    private final PreCustomerUnifyUpdateMapper preCustomerUnifyUpdateMapper;

    private final OauthTokenMapper oauthTokenMapper;

    private final OauthChannelMapper oauthChannelMapper;

    private final CustomerUnifyMapper customerUnifyMapper;

    private final PropertiesConfig propertiesConfig;

    private final UnifySmsAccountMapper unifySmsAccountMapper;

    private final CustomerCancelFlowMapper customerCancelFlowMapper;

    private final CustomerUntieFlowMapper customerUntieFlowMapper;

    private final CustomerExtendCreditMapper customerExtendCreditMapper;

    private final CompanyModifyFlowMapper companyModifyFlowMapper;

    private final OauthLoginFlowMapper oauthLoginFlowMapper;

    private final CustInvitationCodeMapper invitationCodeMapper;

    private final CustInvitationRelationMapper invitationRelationMapper;

    private final UnifySmsPwdMapper pwdFlowMapper;

    @Autowired
    public CommonServiceImpl(PreCustomerMapper preCustomerMapper, CustomerContactInfoMapper customerContactInfoMapper, CustomerMapper customerMapper, CustomMapper customMapper, CustomerIdInfoMapper customerIdInfoMapper, CustomerExtendMapper customerExtendMapper, SystemInfoMapper systemInfoMapper, CustomerRelationInfoMapper relationMapper, ProductInfoMapper productMapper, CustomerProductMapper customerProductMapper, CustomerAccountMapper customerAccountMapper, DictMapperMapper dictMapperMapper, CustomerRoleMapper customerRoleMapper, NoticeLogMapper noticeLogMapper, CustomerContactFlowMapper contactFlowMapper, CompanyIdInfoMapper companyIdInfoMapper, CustomerManageInfoMapper customerManageInfoMapper, PreCustomerPassMapper preCustomerPassMapper,
                             PreCustomerUnifyRegisterMapper preCustomerUnifyRegisterMapper, PreCustomerUnifyLoginMapper preCustomerUnifyLoginMapper, UnifySmsMapper unifySmsMapper, PreCustomerUnifyUpdateMapper preCustomerUnifyUpdateMapper, OauthTokenMapper oauthTokenMapper, OauthChannelMapper oauthChannelMapper, CustomerUnifyMapper customerUnifyMapper, PropertiesConfig propertiesConfig, UnifySmsAccountMapper unifySmsAccountMapper, CustomerCancelFlowMapper customerCancelFlowMapper, CustomerUntieFlowMapper customerUntieFlowMapper, CustomerExtendCreditMapper customerExtendCreditMapper, CompanyModifyFlowMapper companyModifyFlowMapper, OauthLoginFlowMapper oauthLoginFlowMapper
            , CustInvitationCodeMapper invitationCodeMapper, CustInvitationRelationMapper invitationRelationMapper, UnifySmsPwdMapper pwdFlowMapper) {
        this.preCustomerMapper = preCustomerMapper;
        this.customerContactInfoMapper = customerContactInfoMapper;
        this.customerMapper = customerMapper;
        this.customMapper = customMapper;
        this.customerIdInfoMapper = customerIdInfoMapper;
        this.customerExtendMapper = customerExtendMapper;
        this.systemInfoMapper = systemInfoMapper;
        this.relationMapper = relationMapper;
        this.productMapper = productMapper;
        this.customerProductMapper = customerProductMapper;
        this.customerAccountMapper = customerAccountMapper;
        this.dictMapperMapper = dictMapperMapper;
        this.customerRoleMapper = customerRoleMapper;
        this.noticeLogMapper = noticeLogMapper;
        this.contactFlowMapper = contactFlowMapper;
        this.companyIdInfoMapper = companyIdInfoMapper;
        this.customerManageInfoMapper = customerManageInfoMapper;
        this.preCustomerPassMapper = preCustomerPassMapper;
        this.preCustomerUnifyRegisterMapper = preCustomerUnifyRegisterMapper;
        this.unifySmsMapper = unifySmsMapper;
        this.preCustomerUnifyLoginMapper = preCustomerUnifyLoginMapper;
        this.preCustomerUnifyUpdateMapper = preCustomerUnifyUpdateMapper;
        this.oauthTokenMapper = oauthTokenMapper;
        this.oauthChannelMapper = oauthChannelMapper;
        this.customerUnifyMapper = customerUnifyMapper;
        this.propertiesConfig = propertiesConfig;
        this.unifySmsAccountMapper = unifySmsAccountMapper;
        this.customerCancelFlowMapper = customerCancelFlowMapper;
        this.customerUntieFlowMapper = customerUntieFlowMapper;
        this.customerExtendCreditMapper = customerExtendCreditMapper;
        this.companyModifyFlowMapper = companyModifyFlowMapper;
        this.oauthLoginFlowMapper = oauthLoginFlowMapper;
        this.invitationCodeMapper = invitationCodeMapper;
        this.invitationRelationMapper = invitationRelationMapper;
        this.pwdFlowMapper = pwdFlowMapper;
    }

    @Override
    public void checkRepeatRequestNo(String requestNo, TableEnum tableEnum) {
        try {
            if (!CustomerUtils.isValid(requestNo)) {
                throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "请求流水号不符合规则");
            }
            StringBuilder sb = new StringBuilder("select count(id) as count from ");
            sb.append(tableEnum.getValue());
            sb.append(" where request_no=");
            sb.append("'");
            sb.append(requestNo);
            sb.append("'");
            List<LinkedHashMap<String, Object>> linkedHashMaps = customMapper.customQueryItem(sb.toString());
            long count = 0;
            if (linkedHashMaps.size() > 0) {
                count = (long) linkedHashMaps.get(0).get("count");
            }
            if (count > 0) {
                log.info("请求流水号重复:{}", requestNo);
                throw new CustomerException(CustomerCodes.REQUESTNO_REPEAT, "请求流水号重复");
            }
        } catch (DataAccessException e) {
            log.error("查询重复的请求流水号失败:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }

    }

    /**
     * 获取已经存在的用户
     *
     * @param preCustomerNo 客户号
     * @return 用户信息
     */
    @Override
    public PreCustomerInfoPo getExistPreCustomer(String preCustomerNo) {
        try {
            PreCustomerInfoPo po = new PreCustomerInfoPo();
            po.setPreCustomerNo(preCustomerNo);
            List<PreCustomerInfoPo> list = preCustomerMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询用户报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    /**
     * 用户号是否存在
     *
     * @param contactType 联系方式类型
     * @param contactInfo 联系方式
     * @return 用户信息
     */
    @Override
    public PreCustomerInfoPo getExistPreCustomer(String contactType, String contactInfo) {
        try {
            PreCustomerInfoPo po = new PreCustomerInfoPo();
            po.setContactType(contactType);
            po.setContactInfo(contactInfo);
            List<PreCustomerInfoPo> list = preCustomerMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询用户报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public void insertCompanyIdInfo(CompanyIdInfoRo companyIdInfoRo, String customerNo, String subSystemSign) {
        try {
            CompanyIdInfoPo po = new CompanyIdInfoPo();
            po.setCustomerNo(customerNo);
            po.setId(UUIDUtils.getUUID());
            po.setUnifiedCode(companyIdInfoRo.getUnifiedCode());
            po.setLicenseNo(companyIdInfoRo.getLicenseNo());
            po.setOrgNo(companyIdInfoRo.getOrgNo());
            po.setTaxNo(companyIdInfoRo.getTaxNo());
            po.setCustomerName(companyIdInfoRo.getCustomerName());
            po.setLegalName(companyIdInfoRo.getLegalName());
            po.setIdCardNo(companyIdInfoRo.getIdCardNo());
            po.setIdCardType(companyIdInfoRo.getIdCardType());
            po.setElementsVerified(companyIdInfoRo.getElementsVerified() ? CustomerConstants.STATUS_ELEMENTS_VERIFIED : CustomerConstants.STATUS_ELEMENTS_UNVERIFIED);
            if (StringUtils.isNotBlank(companyIdInfoRo.getElementsTime())) {
                po.setElementsTime(CustomerUtils.stirng2Timestamp(companyIdInfoRo.getElementsTime()));
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCustomerType())) {
                po.setCustomerType(companyIdInfoRo.getCustomerType());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCustomerPhoneNo())) {
                po.setCustomerPhoneNo(companyIdInfoRo.getCustomerPhoneNo());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCustomerCertNo())) {
                po.setCustomerCertNo(companyIdInfoRo.getCustomerCertNo());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCorprateCertExpiry())) {
                po.setCorprateCertExpiry(companyIdInfoRo.getCorprateCertExpiry());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCorprateCertExpiryend())) {
                po.setCorprateCertExpiryend(companyIdInfoRo.getCorprateCertExpiryend());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCorprateMobile())) {
                po.setCorprateMobile(companyIdInfoRo.getCorprateMobile());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getOperatorName())) {
                po.setOperatorName(companyIdInfoRo.getOperatorName());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getOperatorCertType())) {
                po.setOperatorCertType(companyIdInfoRo.getOperatorCertType());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getOperatorCertNo())) {
                po.setOperatorCertNo(companyIdInfoRo.getOperatorCertNo());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getOperatorCertExpiry())) {
                po.setOperatorCertExpiry(companyIdInfoRo.getOperatorCertExpiry());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getOperatorCertExpiryend())) {
                po.setOperatorCertExpiryend(companyIdInfoRo.getOperatorCertExpiryend());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getOperatorMobile())) {
                po.setOperatorMobile(companyIdInfoRo.getOperatorMobile());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCustomerCertPid())) {
                po.setCustomerCertPid(companyIdInfoRo.getCustomerCertPid());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCorpratePic1())) {
                po.setCorpratePic1(companyIdInfoRo.getCorpratePic1());
            }
            if (StringUtils.isNotBlank(companyIdInfoRo.getCorpratePic2())) {
                po.setCorpratePic2(companyIdInfoRo.getCorpratePic2());
            }
            //依据子系统标识判断当前客户号对应系统
            po.setSubSystemSign(subSystemSign);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            companyIdInfoMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("更新company_id_info报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void insertCustomerIdInfo(CustomerIdInfoRo ro, String customerNo, String subSystemSign, String remark, boolean isPre) {
        try {
            CustomerIdInfoPo po = new CustomerIdInfoPo();
            po.setId(UUIDUtils.getUUID());
            po.setCustomerNo(customerNo);
            po.setCustomerName(ro.getCustomerName());
            po.setIdCardType(ro.getIdCardType());
            po.setIdCardNo(ro.getIdCardNo());
            po.setElementsVerified((ro.getElementsVerified() != null && ro.getElementsVerified()) ? CustomerConstants.STATUS_ELEMENTS_VERIFIED : CustomerConstants.STATUS_ELEMENTS_UNVERIFIED);
            if (StringUtils.isNotBlank(remark)) {
                po.setRemark(remark);
            }
            if (StringUtils.isNotBlank(ro.getElementsTime())) {
                po.setElementsTime(CustomerUtils.stirng2Timestamp(ro.getElementsTime()));
            }
            if (isPre) {
                po.setCustomerProperty(CustomerConstants.CUSTOMER_PROPERTY_PRE);
            } else {
                po.setCustomerProperty(CustomerConstants.CUSTOMER_PROPERTY_OFFICIAL);
            }
            //依据子系统标识判断当前客户号对应系统
            po.setSubSystemSign(subSystemSign);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            customerIdInfoMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("更新cust_id_info报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void insertContactFlow(CustomerContactFlowPo po) {
        try {
            contactFlowMapper.insert(po);
        } catch (DataAccessException e) {
            log.error("插入cust_contact_flow异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    /**
     * 客户号是否存在
     *
     * @param customerNo 客户号
     * @return 客户信息
     */
    @Override
    public CustomerInfoPo getExistCustomer(String customerNo) {
        try {
            CustomerInfoPo po = new CustomerInfoPo();
            po.setCustomerNo(customerNo);
            List<CustomerInfoPo> list = customerMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.error("查询cust_info异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    /**
     * 客户号是否存在
     *
     * @param customerNo 客户号
     * @return 客户信息
     */
    @Override
    public CustomerIdInfoPo getExistCustomer(String customerNo, String systemSign, String subSystemSign) {
        try {
            List<CustomerIdInfoPo> list = customerIdInfoMapper.getCustomerInfo(customerNo, systemSign, subSystemSign);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustomerIdInfoPo getExistCustomerInfo(String customerName, String idCardType, String idCardNo) {
        try {
            CustomerIdInfoPo po = new CustomerIdInfoPo();
            po.setCustomerName(customerName);
            po.setIdCardType(idCardType);
            po.setIdCardNo(idCardNo);
            List<CustomerIdInfoPo> list = customerIdInfoMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询客户证件信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public int updateCustomerNo4SyncData(String userId, String customerNo, String preCustomerNo, String systemSign, String subSystemSign) {
        try {
            Example example = new Example(CustomerProductInfoPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("userSourceId", userId);
            criteria.andEqualTo("systemSign", systemSign);
            criteria.andEqualTo("subSystemSign", subSystemSign);
            CustomerProductInfoPo po = new CustomerProductInfoPo();
            po.setCustomerNo(customerNo);
            po.setPreCustomerNo(preCustomerNo);
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            return customerProductMapper.updateByExampleSelective(po, example);
        } catch (Exception e) {
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }

    }

    @Override
    public CustomerExtendPo getExistPreCustomerExtend(String preCustomerNo, String systemSign, String subSystemSign) {
        try {
            CustomerExtendPo po = new CustomerExtendPo();
            po.setPreCustomerNo(preCustomerNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            //todo 只查询状态正常的
            po.setStatus(1);
            List<CustomerExtendPo> list = customerExtendMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询用户报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustomerExtendPo getRegisterSystem(String preCustomerNo, String systemSign) {
        try {
            CustomerExtendPo po = customerExtendMapper.getRegisterSystem(preCustomerNo, systemSign);
            return po;
        } catch (DataAccessException e) {
            log.info("查询用户报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustomerExtendPo getExistCustomerExtend(String preCustomerNo, String customerNo, String systemSign, String subSystemSign) {
        try {
            CustomerExtendPo po = new CustomerExtendPo();
            po.setPreCustomerNo(preCustomerNo);
            po.setCustomerNo(customerNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            //todo 只查询状态正常的
            po.setStatus(1);
            List<CustomerExtendPo> list = customerExtendMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询用户报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public List<CustomerExtendPo> getExistPreCustomerExtendList(String preCustomerNo, String systemSign, String subSystemSign) {
        try {
            CustomerExtendPo po = new CustomerExtendPo();
            po.setPreCustomerNo(preCustomerNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            List<CustomerExtendPo> list = customerExtendMapper.select(po);
            return list;
        } catch (DataAccessException e) {
            log.info("查询用户报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public List<CustomerExtendPo> getExistAssociatedPreCustomerExtendList(String associatedCustomerNo, String systemSign, String subSystemSign) {
        try {
            CustomerExtendPo po = new CustomerExtendPo();
            po.setAssociatePreNo(associatedCustomerNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            List<CustomerExtendPo> list = customerExtendMapper.select(po);
            return list;
        } catch (DataAccessException e) {
            log.info("查询用户报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    /**
     * 客户号联系方式是否存在
     *
     * @param systemSign    系统标识
     * @param subSystemSign 子系统标识
     * @param contactType   联系方式类型
     * @param contactInfo   联系方式
     * @return 客户联系方式
     */
    @Override
    public CustomerContactInfoPo getExistCustomerContact(String systemSign, String subSystemSign, String contactType, String contactInfo, String customerNo) {
        try {
            CustomerContactInfoPo po = new CustomerContactInfoPo();
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setContactType(contactType);
            po.setContactInfo(contactInfo);
            po.setCustomerNo(customerNo);
            List<CustomerContactInfoPo> list = customerContactInfoMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询客户联系信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustomerContactInfoPo getExistCustomerContact(String systemSign, String subSystemSign, String customerNo) {
        try {
            CustomerContactInfoPo po = new CustomerContactInfoPo();
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setCustomerNo(customerNo);
            List<CustomerContactInfoPo> list = customerContactInfoMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询客户联系信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    /**
     * 插入contact
     *
     * @param ro         contact请求实体
     * @param customerNo 客户号
     * @param request    请求实体
     * @param remark     备注
     */
    @Override
    public void insertCustomerContactInfo(ContactRo ro, String customerNo, BaseRequest request, String remark) {
        try {
            CustomerContactInfoPo po = new CustomerContactInfoPo();
            po.setId(UUIDUtils.getUUID());
            po.setCustomerNo(customerNo);
            po.setContactInfo(ro.getContactInfo());
            po.setContactType(ro.getContactType());
            po.setContactVerified(((ro.getContactVerified() != null && ro.getContactVerified()) ? CustomerConstants.STATUS_CONTACT_VERIFIED : CustomerConstants.STATUS_CONTACT_UNVERIFIED));
            if (StringUtils.isNotBlank(remark)) {
                po.setRemark(remark);
            }
            po.setSystemSign(request.getSystemSign());
            po.setSubSystemSign(request.getSubSystemSign());
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            customerContactInfoMapper.insert(po);
        } catch (DataAccessException e) {
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    /**
     * 联系信息变更校验流水号是否重复 原联系方式是否存在 客户号/用户号是否存在
     *
     * @param request    request
     * @param customerNo 客户号
     * @param isPre      是不是用户
     */
    @Override
    public void checkContactModifyParam(BaseRequest<CustomerContactModifyRo> request, String customerNo, boolean isPre) {
        //校验请求流水号重复
        String requestNo = request.getBody().getRequestNo();
        checkRepeatRequestNo(requestNo, TableEnum.CONTACT_FLOW);
        String oldContactType = request.getBody().getContactTypeOld();
        String oldContactInfo = request.getBody().getContactInfoOld();
        String systemSign = request.getSystemSign();
        String subSystemSign = request.getSubSystemSign();
        if (isPre) {
            //判断当前用户号是否有其他关联用户号
            CustomerExtendPo existPreCustomerExtend = getExistPreCustomerExtend(customerNo, systemSign, subSystemSign);
            if (existPreCustomerExtend == null) {
                throw new CustomerException(CustomerCodes.PRE_CUSTOMERNO_NOT_EXIST);
            } else {
                if (StringUtils.isNotBlank(existPreCustomerExtend.getCustomerNo())) {
                    String message = "该客户已经转化为客户,客户号为'" + existPreCustomerExtend.getCustomerNo() + "',请修改客户号对应的联系方式";
                    throw new CustomerException(CustomerCodes.PRE_CUSTOMERNO_CONVERTED, message);
                }
            }

            List<CustomerExtendPo> list = getExistAssociatedPreCustomerExtendList(customerNo, systemSign, subSystemSign);
            if (list.size() > 0) {
                String message = "该客户号已被其他用户号关联,客户号为'" + list.get(0).getPreCustomerNo() + "',请修改对应客户号的联系方式";
                throw new CustomerException(CustomerCodes.PRE_CUSTOMERNO_CONVERTED, message);
            }

            if (StringUtils.isNotBlank(oldContactType) && StringUtils.isNotBlank(oldContactInfo)) {
                PreCustomerInfoPo perCustomer = getExistPreCustomer(oldContactType, oldContactInfo);
                if (perCustomer == null) {
                    throw new CustomerException(CustomerCodes.BIZ_VALIDATE_ERROR, "客户对应的原联系方式不存在");
                }
            }
        } else {
            CustomerIdInfoPo idInfoPo = getExistCustomer(customerNo, systemSign, subSystemSign);
            if (idInfoPo == null) {
                throw new CustomerException(CustomerCodes.CUSTOMERNO_NOT_EXIST, "客户号" + customerNo + "不存在");
            }
            if (StringUtils.isBlank(oldContactType) || StringUtils.isBlank(oldContactInfo)) {
                CustomerContactInfoPo po = new CustomerContactInfoPo();
                po.setCustomerNo(customerNo);
                po.setSystemSign(systemSign);
                po.setSubSystemSign(subSystemSign);
                int count = customerContactInfoMapper.selectCount(po);
                if (count == 0) {
                    throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "原联系信息不存在");
                } else if (count > 1) {
                    throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "原联系信息存在多个，请填写原联系信息");
                }
            } else {
                CustomerContactInfoPo cerCustomer = getExistCustomerContact(request.getSystemSign(), request.getSubSystemSign(), oldContactType, oldContactInfo, customerNo);
                if (cerCustomer == null) {
                    throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "原联系信息不存在");
                }
            }

        }
    }

    /**
     * 客户号是否存在
     *
     * @param customerNo 客户号
     * @return 客户信息
     */
    @Override
    public List<CustomerIdInfoPo> getAllCustomer(String customerNo, String systemSign, String subSystemSign) {
        try {
            List<CustomerIdInfoPo> list = customerIdInfoMapper.getCustomerInfo(customerNo, systemSign, subSystemSign);
            return list;
        } catch (DataAccessException e) {
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
//    @Async("myTaskAsyncPool")
    public String sendHttpMsg(String receiver, String id, String customerNo, String customerName, String idCardType, String idCardNo, String oldCustomerName, String oldIdCardType, String oldIdCardNo) {
        JSONObject param1 = new JSONObject();
        param1.put("idCardType", idCardType);
        param1.put("idCardNo", idCardNo);
        param1.put("customerName", customerName);
        JSONObject param = new JSONObject();
        param.put("customerNo", customerNo);
        param.put("idInfo", param1);
        Example example = new Example(SystemInfoPo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("systemSign", receiver);
        List<SystemInfoPo> pos = systemInfoMapper.selectByExample(example);
        String jsonDate = param.toString();
        String url = pos.get(0).getServiceUrl();
        String systemSign = pos.get(0).getSystemSign();
        String noticeRes = "1";
        CustomerContactFlowPo po = new CustomerContactFlowPo();
        po.setId(UUIDUtils.getUUID());
        po.setRequestNo(id);
        po.setCustomerNo(customerNo);
        po.setModifyType(CustomerConstants.MODIFY_TYPE_ELEMENTS);
        po.setCustomerName(customerName);
        po.setSubSystemSign(receiver);
        po.setContactInfo(idCardNo);
        po.setContactInfoOld(oldIdCardNo);
        po.setContactTypeOld(oldIdCardType);
        po.setContactType(idCardType);
        po.setCustomerNameOld(oldCustomerName);
        po.setNoticeStatus(CustomerConstants.NOTICE_STATUS_FAIL);
        if (url != null && url.length() != 0) {
            try {
                String result = HttpClientUtil.postJSON(url, jsonDate, null, null);
                JSONObject jsStr = JSONObject.parseObject(result);
                //返回结果code为0，表示通知成功
                if ("0".equals(jsStr.getString("code"))) {
                    noticeRes = "0";
                    po.setNoticeStatus(CustomerConstants.NOTICE_STATUS_SUCCESS);
                }
                log.info("发送业务端:" + systemSign + " 返回信息:" + result);
            } catch (Exception e) {
                log.info("发送业务端报错:" + systemSign + " 返回信息:" + e);
            }
        }
        //待处理
        po.setStatus(CustomerConstants.STATUS_TODO);
        po.setCreateTime(new Timestamp(System.currentTimeMillis()));
        po.setCreateDate(new Date(System.currentTimeMillis()));
        contactFlowMapper.insert(po);
        return noticeRes;
    }

    @Override
    @Async("myTaskAsyncPool")
    public void sendEmail(EmailSendRo ro) {
        AlarmUtils.sendMail(ro);
    }

    @Override
    public String sendMergeNotice(String receiver, String id, String customerNo, String customerName, String idCardType, String idCardNo, String mergeCustomerNo) {
        JSONObject param1 = new JSONObject();
        param1.put("idCardType", idCardType);
        param1.put("idCardNo", idCardNo);
        param1.put("customerName", customerName);
        JSONObject param = new JSONObject();
        param.put("customerNo", customerNo);
        param.put("idInfo", param1);
        Example example = new Example(SystemInfoPo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("systemSign", receiver);
        List<SystemInfoPo> pos = systemInfoMapper.selectByExample(example);
        String jsonData = param.toString();
        String url = pos.get(0).getServiceUrl();
        String systemSign = pos.get(0).getSystemSign();
        String noticeRes = "1";
        NoticeLogPo noticeLogPo = new NoticeLogPo();
        noticeLogPo.setId(UUIDUtils.getUUID());
        noticeLogPo.setNoticeId(id);
        noticeLogPo.setNoticeContent(jsonData);
        noticeLogPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
        noticeLogPo.setSubSystemSign(systemSign);
        noticeLogPo.setMergeCustomerNo(mergeCustomerNo);
        noticeLogPo.setReceiptStatus(CustomerConstants.NOTICE_RECEIPT_TODO);
        noticeLogPo.setNoticeStatus(CustomerConstants.NOTICE_STATUS_FAIL);
        if (url != null && url.length() != 0) {
            try {
                String result = HttpClientUtil.postJSON(url, jsonData, null, null);
                JSONObject jsStr = JSONObject.parseObject(result);
                //返回结果code为0，表示通知成功
                if ("0".equals(jsStr.getString("code"))) {
                    noticeRes = "0";
                    noticeLogPo.setNoticeStatus(CustomerConstants.NOTICE_STATUS_SUCCESS);
                }
                log.info("发送业务端信息:" + systemSign + " 返回信息:" + result);
            } catch (Exception e) {
                log.info("发送业务端报错:" + systemSign + " 返回信息:" + e);
            }
        }
        noticeLogMapper.insert(noticeLogPo);
        return noticeRes;
    }

    @Override
    public boolean verifySign(String data, String signature, SystemInfoPo system) throws GeneralSecurityException {
        Signature verifySign;
        String publicKeySource = system.getPublicKey();
        if (StringUtils.isNotBlank(publicKeySource)) {
            KeyFactory gen = KeyFactory.getInstance(CustomerConstants.KEY_ALGORITHM);
            byte[] publicE = Base64.decodeBase64(publicKeySource);
            PublicKey publicKey = gen.generatePublic(new X509EncodedKeySpec(publicE));
            verifySign = Signature.getInstance("SHA1withRSA");
            verifySign.initVerify(publicKey);
            verifySign.update(data.getBytes());
            return verifySign.verify(Base64.decodeBase64(signature));
        } else {
            throw new CustomerException(CustomerCodes.SIGN_EXCEPTION);
        }
    }


    @Override
    public void updateRelation(String systemSign, String subSystemSign, String oldPreCustomerNo, String newPreCustomerNo) {
        try {
            Example example = new Example(CustomerRelationInfoPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("customerNo", oldPreCustomerNo);
            criteria.andEqualTo("systemSign", systemSign);
            criteria.andEqualTo("subSystemSign", subSystemSign);
            CustomerRelationInfoPo po = new CustomerRelationInfoPo();
            po.setCustomerNo(newPreCustomerNo);
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            relationMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.error("更新关系信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updateCustomerProduct(String systemSign, String subSystemSign, String oldPreCustomerNo, String newPreCustomerNo) {
        try {
            Example example = new Example(CustomerProductInfoPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("systemSign", systemSign);
            criteria.andEqualTo("subSystemSign", subSystemSign);
            criteria.andEqualTo("preCustomerNo", oldPreCustomerNo);
            CustomerProductInfoPo po = new CustomerProductInfoPo();
            po.setPreCustomerNo(newPreCustomerNo);
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            customerProductMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.error("更新用户信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public ProductInfoPo getProductInfo(String tableKey, String systemSign, String subSystemSign) {
        try {
            ProductInfoPo po = new ProductInfoPo();
            po.setTableKey(tableKey);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            return productMapper.selectOne(po);
        } catch (DataAccessException e) {
            log.error("查询产品信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustomerProductInfoPo getCustomerProduct(String userSourceId, String productNo, String tableName, String tableKey) {
        try {
            CustomerProductInfoPo po = new CustomerProductInfoPo();
            po.setUserSourceId(userSourceId);
            //po.setProductNo(productNo);
            po.setTableName(tableName);
            po.setTableKey(tableKey);
            return customerProductMapper.selectOne(po);
        } catch (DataAccessException e) {
            log.error("查询客户产品信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustomerAccountPo getCustomerAccount(String userSourceId, String accountNo, String systemSign, String subSystemSign, Integer status) {
        try {
            CustomerAccountPo po = new CustomerAccountPo();
            po.setUserSourceId(userSourceId);
            po.setAccountNo(accountNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setAccountStatus(status);
            CustomerAccountPo customerAccountPo = null;
            try {
                customerAccountPo = customerAccountMapper.selectOne(po);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return customerAccountPo;
        } catch (DataAccessException e) {
            log.error("查询客户账户信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            //return null;
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustomerAccountPo getCustomerAccount(String userSourceId, String accountNo, String systemSign, String subSystemSign) {
        try {
            CustomerAccountPo po = new CustomerAccountPo();
            po.setUserSourceId(userSourceId);
            po.setAccountNo(accountNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            CustomerAccountPo customerAccountPo = null;
            try {
                customerAccountPo = customerAccountMapper.selectOne(po);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return customerAccountPo;
        } catch (DataAccessException e) {
            log.error("查询客户账户信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public DictMapperPo getDictMapper(String mapperType, String code, String systemSign, String subSystemSign) {
        try {
            DictMapperPo po = new DictMapperPo();
            po.setMapperType(mapperType);
            po.setCode(code);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            return dictMapperMapper.selectOne(po);
        } catch (DataAccessException e) {
            log.error("查询产品类型报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public SystemInfoPo getSystemInfo(String systemSign, String subSystemSign) {
        try {
            SystemInfoPo po = new SystemInfoPo();
            po.setParentId(systemSign);
            po.setSystemSign(subSystemSign);
            return systemInfoMapper.selectOne(po);
        } catch (DataAccessException e) {
            log.error("查询系统标识报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public SystemInfoPo getSystemInfo(String productCode) {
        try {
            SystemInfoPo po = new SystemInfoPo();
            po.setChannelNo(productCode);
            List<SystemInfoPo> list = systemInfoMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.error("查询sys_info异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public String getRoleSource(String systemSign, String subSystemSign) {
        try {
            SystemInfoPo systemInfo = getSystemInfo(systemSign, subSystemSign);
            return systemInfo.getRoleSource();
        } catch (Exception e) {
            log.error("获取角色来源报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            return null;
        }
    }

    @Override
    public String getRelationSource(String systemSign, String subSystemSign) {
        try {
            SystemInfoPo systemInfo = getSystemInfo(systemSign, subSystemSign);
            return systemInfo.getRelationSource();
        } catch (Exception e) {
            log.error("获取关系来源报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            return null;
        }
    }

    @Override
    public CustomerRolePo getCustomerRole(String customerNo, String role, String systemSign, String subSystemSign) {
        try {
            CustomerRolePo po = new CustomerRolePo();
            po.setCustomerNo(customerNo);
            po.setCustomerRole(role);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            return customerRoleMapper.selectOne(po);
        } catch (Exception e) {
            log.error("获取用户角色报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            return null;
        }
    }

    @Override
    public String getCustomerRoleSource(String userSourceId, String systemSign, String subSystemSign) {
        /*String roleSource = getRoleSource(systemSign, subSystemSign);
        String destRole = null;
        if(StringUtils.isNotBlank(roleSource)){
            if(!CustomerConstants.RELATION_SOURCE_LIST.contains(roleSource)){
                //表示角色是固定值
                destRole =  roleSource;
            } else if (CustomerConstants.ROLE_SOURCE_PRODUCT.equals(roleSource)){
                //TODO 表示要从产品购买记录分析出角色 destRole = ??
                destRole =  null;
            }

            if(StringUtils.isNotBlank(destRole)){
                CustomerRolePo customerRole = commonService.getCustomerRole(userSourceId, destRole, systemSign, subSystemSign);
                if(customerRole == null){
                    return destRole;
                }
            }
        }*/
        return null;
    }


    @Override
    public CompanyIdInfoPo getCompanyInfo(String unifiedCode, String licenseNo, String orgNo, String taxNo) {
        try {
            CompanyIdInfoPo po = new CompanyIdInfoPo();
            po.setUnifiedCode(unifiedCode);
            po.setLicenseNo(licenseNo);
            po.setOrgNo(orgNo);
            po.setTaxNo(taxNo);
            List<CompanyIdInfoPo> list = companyIdInfoMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询企业证件信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }


    @Override
    public List<CustomerManageInfoPo> getCustomerManageInfo(String customerNo) {
        try {
            CustomerManageInfoPo po = new CustomerManageInfoPo();
            po.setCustomerNo(customerNo);
            List<CustomerManageInfoPo> list = customerManageInfoMapper.select(po);
            return list;
        } catch (DataAccessException e) {
            log.info("查询cust_manage_info报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    // 新注册用户 及直接调创建用户号接口
    @Override
    public void insertPreCustomerPass(String preCustomerNo, String systemSign, String subSystemSign, String password, String mobile) {
        try {
            PreCustomerPasswdPo po = new PreCustomerPasswdPo();
            po.setMobile(mobile);
            po.setPreCustomerNo(preCustomerNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            po.setPasswd(EncryptUtils.getYztSha1(password));
            po.setLockState(1);
            preCustomerPassMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("创建统一用户密码信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void insertCustUnifyRegisterFlow(String phone, String systemSign, String subSystemSign, String requestNo, Integer status, String errorMsg, String password) {
        PreCustomerUnifyRegisterFlowPo po = new PreCustomerUnifyRegisterFlowPo();
        po.setPhone(phone);
        po.setSystemSign(systemSign);
        po.setSubSystemSign(subSystemSign);
        po.setRequestNo(requestNo);
        po.setStatus(status);
        po.setErrorMsg(errorMsg);
        po.setPassword(password);
        po.setCreateTime(new Timestamp(System.currentTimeMillis()));
        preCustomerUnifyRegisterMapper.insert(po);
    }

    @Override
    public CustomerExtendPo getCustomerUnifyInfo(String preCustomerNo, String customerNo, String systemSign, String subSystemSign) {
        try {
            List<CustomerExtendPo> list = customerExtendMapper.getCustomerUnifyInfo(preCustomerNo, customerNo, systemSign, subSystemSign);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("统一登录查询客户信息报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }


    @Override
    public void sendSms(String mobile, String content, String systemSign, String subSystemSign, String type) {
        String errorMsg = null;
        try {
            String url = propertiesConfig.getSmsUrl();
            UnifySmsAccountPo po = new UnifySmsAccountPo();
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setTemplateType(type);
            //当为配置手机号段时，发送固定短信验证码
            Map<String, String> fixedCodeDictMap = DictionaryFactory.Dict.UNIFY_FIXED_CODE.getDictMap();
            String fixedCodeRule = fixedCodeDictMap.get("HSH");
            if (StringUtils.isNotBlank(fixedCodeRule)) {
                String[] rule = fixedCodeRule.split("/");
                String fixedPhone = rule[1];
                if (fixedPhone.contains(mobile)) {
                    content = rule[0];
                }
            }
            List<UnifySmsAccountPo> pos = unifySmsAccountMapper.select(po);
            if (pos != null && pos.size() > 0) {
                JSONObject jsonMessage = new JSONObject();
                jsonMessage.put("accountCode", pos.get(0).getSmsAccount());
                jsonMessage.put("isAsync", "N");
                jsonMessage.put("isAudioSend", "");
                jsonMessage.put("isMuitle", "");
                jsonMessage.put("smsTemplateId", pos.get(0).getSmsTemplateId());
                if (CustomerConstants.XHSC.equals(subSystemSign)) {
                    jsonMessage.put("sendContent", "[{'mobile':" + mobile + ",'map':{'vcode':" + content + ",'servicephone':'4006-873-073'}}]");
                } else if (CustomerConstants.BDSHM.equals(subSystemSign) && CustomerConstants.SMS_TEMPLATE_TZ.equals(type)) {
                    jsonMessage.put("sendContent", "[{'mobile':" + mobile + ",'map':{'phone':" + content + "}}]");
                } else {
                    jsonMessage.put("sendContent", "[{'mobile':" + mobile + ",'map':{'code':" + content + "}}]");
                }
                String message = jsonMessage.toJSONString();
//            String message = '{"accountCode":"fengqi-tuike-yzm","isAsync":"N","isAudioSend":"","isMuitle":"","sendContent":"[{\"mobile\":\"13683348480\",\"map\":{\"code\":\"1234567\"}}]","sendTime":"","smsTemplateId":"2120"}';
                Map<String, String> paramMap = new HashMap<>(2);
                paramMap.put("message", message);
                String smsResponse = HttpClientUtil.postFormData(url, paramMap, null, null);
                log.info("短信服务返回结果：>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>{}", smsResponse);
                JSONObject jsonObject = JSON.parseObject(smsResponse);
                errorMsg = jsonObject.getString("sendLog");
                if ("F".equals(jsonObject.getString("sendResult"))) {
                    log.error("短信服务返回结果：>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>{}", errorMsg);
                    throw new CustomerException(CustomerCodes.SMS_INTERFACE_ERROR, "操作过于频繁，请稍后再试！");
                }
            } else {
                throw new CustomerException(CustomerCodes.PARAM_VALIDATE_ERROR, "当前系统未配置短信账号，请联系管理员！");
            }
        } catch (Exception e) {
            log.error("调用短信发送异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            if (e instanceof CustomerException) {
                throw new CustomerException(((CustomerException) e).getCode(), ((CustomerException) e).getMsg());
            } else {
                throw new CustomerException(CustomerCodes.SMS_INTERFACE_ERROR, "短信平台异常，请稍后再试！");
            }
        }

    }

    @Override
    public void insertCustUnifySmsFlow(String phone, String systemSign, String subSystemSign, String requestNo, Integer status, String errorMsg, String smsCode, String ip) {
        try {
            UnifySmsCodeFlowPo po = new UnifySmsCodeFlowPo();
            po.setPhone(phone);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setRequestNo(requestNo);
            po.setStatus(status);
            po.setErrorMsg(errorMsg);
            po.setSmsCode(smsCode);
            po.setIp(ip);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            unifySmsMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入cust_unify_sms_flow报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void updateCustUnifySmsFlow(Timestamp unlockTime, Integer id) {
        try {
            Example example = new Example(UnifySmsCodeFlowPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id", id);
            UnifySmsCodeFlowPo po = new UnifySmsCodeFlowPo();
            po.setUnlockTime(unlockTime);
            unifySmsMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_unify_sms_flow表异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void insertCustUnifyUpdateFlow(String requestParam, String systemSign, String subSystemSign, String requestNo, Integer status, String errorMsg) {
        try {
            CustomerUnifyUpdateFlowPo po = new CustomerUnifyUpdateFlowPo();
            po.setRequestNo(requestNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setRequiredParam(requestParam);
            po.setStatus(status);
            po.setErrorMsg(errorMsg);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            preCustomerUnifyUpdateMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入更新表报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void insertCustUnifyLoginFlow(String phone, String systemSign, String subSystemSign, String requestNo, Integer status, String errorMsg, String password, String smsCode, String loginCode) {
        try {
            PreCustomerUnifyLoginFlowPo po = new PreCustomerUnifyLoginFlowPo();
            po.setPhone(phone);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setRequestNo(requestNo);
            po.setStatus(status);
            po.setErrorMsg(errorMsg);
            po.setSmsCode(smsCode);
            po.setPassword(password);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            if (StringUtils.isNotBlank(loginCode)) {
                po.setRemark(loginCode);
            }
            preCustomerUnifyLoginMapper.insert(po);
        } catch (DataAccessException e) {
            log.error("插入登陆流水报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public List<LoginFlowVo> getCustomerUnifyLoginFlowList(String subSystemSign, String phone, Integer status, String password, List<String> time) {
        try {
            LoginFlowRo ro = new LoginFlowRo();
            ro.setSubSystemSign(subSystemSign);
            ro.setPhone(phone);
            ro.setStatus(status);
            ro.setPassword(password);
            ro.setCreateTimeStart(time.get(0));
            ro.setCreateTimeEnd(time.get(1));
            List<LoginFlowVo> list = preCustomerUnifyLoginMapper.getListRecently(ro);
            return list;
        } catch (DataAccessException e) {
            log.info("查询登陆流水报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustOauthTokenPo getOauthCode(String code) {
        try {
            CustOauthTokenPo po = new CustOauthTokenPo();
            po.setLoginCode(code);
            List<CustOauthTokenPo> list = oauthTokenMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询cust_oauth_token报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustOauthTokenPo getOauthCodeInfo(String code, String subSystemSign) {
        try {
            CustOauthTokenPo po = new CustOauthTokenPo();
            po.setLoginCode(code);
            po.setSubSystemId(subSystemSign);
            po.setStatus(1);
            List<CustOauthTokenPo> list = oauthTokenMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查取cust_oauth_token报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustOauthTokenPo getOauthCode(String preCustomerNo, String subSystemId) {
        try {
            CustOauthTokenPo po = new CustOauthTokenPo();
            po.setPreCustomerNo(preCustomerNo);
            po.setSubSystemId(subSystemId);
            List<CustOauthTokenPo> list = oauthTokenMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查取cust_oauth_token报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustOauthChannelPo getOauthChannel(String preCustomerNo, String subSystemId, String channelId) {
        try {
            CustOauthChannelPo po = new CustOauthChannelPo();
            po.setPreCustomerNo(preCustomerNo);
            po.setSubSystemId(subSystemId);
            po.setChannelId(channelId);
            List<CustOauthChannelPo> list = oauthChannelMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查取cust_oauth_channel报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }


    @Override
    public void updateCustOauthToken(String preCustomerNo, String subSystemId, String loginCode, Integer status, Integer regesterStatus, String creditSystem) {
        try {
            CustOauthTokenPo tempPo = new CustOauthTokenPo();
            tempPo.setPreCustomerNo(preCustomerNo);
            tempPo.setSubSystemId(subSystemId);
            List<CustOauthTokenPo> list = oauthTokenMapper.select(tempPo);
            if (list != null && list.size() > 0) {
                CustOauthTokenPo po = list.get(0);
                po.setLoginCode(loginCode);
                if (status != null) {
                    po.setStatus(status);
                }
                if (po.getRegisterStatus() != null && po.getRegisterStatus() != 1) {
                    po.setRegisterStatus(regesterStatus);
                }
                po.setCreditSystem(creditSystem);
                po.setAccessToken("");
                po.setRefreshToken("");
                po.setModifyTime(new Timestamp(System.currentTimeMillis()));
                oauthTokenMapper.updateByPrimaryKeySelective(po);
            }

        } catch (DataAccessException e) {
            log.info("更新cust_oauth_token表异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void insertCustOauthChannel(String preCustomerNo, String systemId, String subSystemId, String channelId) {
        try {
            CustOauthChannelPo po = new CustOauthChannelPo();
            po.setId(UUIDUtils.getUUID());
            po.setSystemId(systemId);
            po.setSubSystemId(subSystemId);
            po.setChannelId(channelId);
            po.setPreCustomerNo(preCustomerNo);
            po.setStatus(1);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            oauthChannelMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入cust_oauth_channel表报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public CustOauthTokenVo getOauthTokenInfo(String accessToken, String subSystemId) {
        try {
            CustOauthTokenPo po = new CustOauthTokenPo();
            po.setAccessToken(accessToken);
            po.setSubSystemId(subSystemId);
            List<CustOauthTokenPo> list = oauthTokenMapper.select(po);
            if (list != null && list.size() > 0) {
                CustOauthTokenPo dataPo = list.get(0);
                //vo.setPreCustomerNo(dataPo.getPreCustomerNo());
                List<CustOauthTokenVo> dataVos = customerUnifyMapper.getCustomerInfo(dataPo.getPreCustomerNo(), null, subSystemId);
                return dataVos.size() > 0 ? dataVos.get(0) : null;
            }
            return null;
        } catch (DataAccessException e) {
            log.info("查取cust_oauth_token报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public void insertCustOauthToken(String preCustomerNo, String systemId, String subSystemId, String loginCode, Integer status, Integer regesterStatus, String creditSystem) {
        try {
            CustOauthTokenPo po = new CustOauthTokenPo();
            po.setId(UUIDUtils.getUUID());
            po.setSystemId(systemId);
            po.setSubSystemId(subSystemId);
            po.setLoginCode(loginCode);
            po.setPreCustomerNo(preCustomerNo);
            if (status != null) {
                po.setStatus(status);
            } else {
                po.setStatus(1);
            }
            if (regesterStatus != null) {
                po.setRegisterStatus(regesterStatus);
            } else {
                po.setRegisterStatus(0);
            }
            po.setCreditSystem(creditSystem);
            po.setAccessToken("");
            po.setRefreshToken("");
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            oauthTokenMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入cust_oauth_token表报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }


    @Override
    public void insertCustomerExtend(String systemSign, String subSystemSign, String remark, String preCustomerNo) {
        try {
            CustomerExtendPo currentPo = new CustomerExtendPo();
            currentPo.setPreCustomerNo(preCustomerNo);
            currentPo.setSystemSign(systemSign);
            currentPo.setSubSystemSign(subSystemSign);
            currentPo.setStatus(1);
            int res = customerExtendMapper.selectCount(currentPo);
            if (res == 0) {
                currentPo.setId(UUIDUtils.getUUID());
                currentPo.setRemark(remark);
                currentPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
                customerExtendMapper.insert(currentPo);
            }
        } catch (DataAccessException e) {
            log.info("插入cust_extend表报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void verifySignature(String mainSystemId, String requestTimestamp, String code, String signature) {
        Timestamp now = new Timestamp(System.currentTimeMillis());
        long time = Long.parseLong(requestTimestamp);
        long residueTime = now.getTime() - time;
        if (residueTime > 1000 * 60 * 3) {
//                map.put("code","1");
//                map.put("msg","超时");
//                return map;
            throw new CustomerException(CustomerCodes.REQUEST_TIME_OUT, "请求时间已超时!");
        }
        SystemInfoPo po = new SystemInfoPo();
        po.setParentId("YZT");
        po.setSystemSign(mainSystemId);
        List<SystemInfoPo> list = systemInfoMapper.select(po);
        String verifyCode = code + requestTimestamp + mainSystemId + list.get(0).getSecretKey();
        if (!signature.equals(EncryptUtils.getSha1(verifyCode))) {
            throw new CustomerException(CustomerCodes.SIGN_FAIL, "验签失败!");
        }
    }

    @Override
    public void verifyH5(String systemSign, String subSystemSign, String requestTimestamp, String signature) {
        Timestamp now = new Timestamp(System.currentTimeMillis());
        long time = Long.parseLong(requestTimestamp);
        long residueTime = now.getTime() - time;
        if (residueTime > 1000 * 60 * 60) {
//                map.put("code","1");
//                map.put("msg","超时");
//                return map;
            throw new CustomerException(CustomerCodes.REQUEST_TIME_OUT, "请求时间已超时!");
        }
        SystemInfoPo po = new SystemInfoPo();
        po.setParentId(systemSign);
        po.setSystemSign(subSystemSign);
        List<SystemInfoPo> list = systemInfoMapper.select(po);
        String verifyCode = requestTimestamp + subSystemSign + list.get(0).getSecretKey();
        if (!signature.equals(EncryptUtils.getSha1(verifyCode))) {
            throw new CustomerException(CustomerCodes.SIGN_FAIL, "验签失败!");
        }
    }

    @Override
    public Map<String, String> custIdentity(String cid, String name) {
        Map<String, String> map = new HashMap<String, String>();
        //组装请求参数
        JSONObject userParam = new JSONObject();
        userParam.put("cid", cid);
        userParam.put("name", name);
        JSONObject param = new JSONObject();
        param.put("rtn", "y");
        param.put("apiname", "identity");
        param.put("thirdEntrance", "07_XYK00001");
        param.put("params", userParam);
        //请求地址
        String url = propertiesConfig.getIdentityUrl();
//        String url = "http://api.bdp.credithc.com/bdp/zcx";
        //头参数
        Map<String, String> headerMap = new HashMap<String, String>();
        headerMap.put("Authorization", "Basic VVNFUjE6ZGxpQUdVMUt1RDU5dGp2dw==");
        //请求
        try {
            String result = HttpClientUtil.postJSON(url, param.toString(), headerMap, null);
            log.info("调用大数据三方返回结果：" + result);
            JSONObject jsStr = JSONObject.parseObject(result);
            String code=jsStr.getString("code");
            if (CustomerConstants.ZCX_SUCEESS_CODE_LIST.contains(code)) {
                //返回结果code为1，表示请求成功 -20000 校验失败
                JSONObject data = jsStr.getJSONObject("body");
                map.put("resCode", data.getString("resCode"));
                map.put("resMsg", data.getString("resMsg"));
            } else if(CustomerConstants.ZCX_FAIL_CODE_LIST.contains(code)){
                map.put("resCode", code);
                map.put("resMsg", jsStr.getString("message"));
            }
            else {
                //失败
                throw new CustomerException(CustomerCodes.BIGDATA_INTERFACE_ERROR, "调用大数据接口异常");
            }
        } catch (Exception e) {
            map.put("resCode", "2501");
            map.put("resMsg", "调用大数据接口异常");
            log.error("调用大数据接口异常:" + e);
        }
        return map;
    }

    /**
     * 客户号是否存在
     *
     * @param customerNo 客户号
     * @return 客户信息
     */
    @Override
    public CustomerIdInfoPo getCustomerIdInfo(String customerNo) {
        try {
            CustomerIdInfoPo po = new CustomerIdInfoPo();
            po.setCustomerNo(customerNo);
            List<CustomerIdInfoPo> list = customerIdInfoMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CompanyIdInfoPo getCompanyIdInfo(String customerNo) {
        try {
            CompanyIdInfoPo po = new CompanyIdInfoPo();
            po.setCustomerNo(customerNo);
            List<CompanyIdInfoPo> list = companyIdInfoMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public void insertCustCancelFlow(String phone, String systemSign, String subSystemSign, String requestNo, Integer status, String errorMsg, String preCustomerNo, String customerNo) {
        try {
            CustomerCancelFlowPo po = new CustomerCancelFlowPo();
            po.setPhone(phone);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setRequestNo(requestNo);
            po.setStatus(status);
            po.setErrorMsg(errorMsg);
            po.setPreCustomerNo(preCustomerNo);
            po.setCustomerNo(customerNo);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            customerCancelFlowMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("注销流水报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void insertCustUntieFlow(String systemSign, String subSystemSign, String requestNo, Integer status, String errorMsg, String preCustomerNo, String customerNo, String name, String idType, String idNo) {
        try {
            CustomerUntieFlowPo po = new CustomerUntieFlowPo();
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setRequestNo(requestNo);
            po.setStatus(status);
            po.setErrorMsg(errorMsg);
            po.setPreCustomerNo(preCustomerNo);
            po.setCustomerNo(customerNo);
            po.setCustomerName(name);
            po.setIdCardNo(idNo);
            po.setIdCardType(idType);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            customerUntieFlowMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("解绑流水报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updateCode(String id, String customerNo, String loginCode) {
        try {
            CustOauthTokenPo po = new CustOauthTokenPo();
            po.setId(id);
            po.setLoginCode(loginCode);
            po.setCustomerNo(customerNo);
            po.setStatus(CustomerConstants.CODE_VALID);
            po.setModifyTime(new Timestamp(System.currentTimeMillis()));
            oauthTokenMapper.updateByPrimaryKeySelective(po);
        } catch (DataAccessException e) {
            log.info("更新cust_oauth_token表异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public CustOauthTokenPo getOauthToken(String accessToken, String subSystemId) {
        try {
            CustOauthTokenPo po = new CustOauthTokenPo();
            po.setAccessToken(accessToken);
            po.setStatus(CustomerConstants.CODE_VALID);
            po.setSubSystemId(subSystemId);
            List<CustOauthTokenPo> list = oauthTokenMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查取cust_oauth_token报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public Map<String, String> getOnlineToken(String systemSign, String subSystemSign, String merchantNo, String courseId, String requestNo, String phone, String preCustomerNo, String riskNo, String money) {
        Map<String, String> map = new HashMap<String, String>();
        //组装请求参数
        JSONObject param = new JSONObject();
        param.put("serviceName", "getOnlineToken");
        param.put("systemSign", systemSign);
        param.put("subSystemSign", subSystemSign);
        param.put("merchantNo", merchantNo);
        param.put("sourceType", "4");
        param.put("courseId", courseId);
        param.put("requestNo", requestNo);
        JSONObject bodyParam = new JSONObject();
        bodyParam.put("phone", phone);
        bodyParam.put("preCustomerNo", preCustomerNo);
        bodyParam.put("riskNo", riskNo);
        bodyParam.put("amount", money);
        param.put("body", bodyParam);
        //请求地址
        String url = propertiesConfig.getBailangUrl();
        //请求
        try {
            String result = HttpClientUtil.postJSON(url, param.toString(), null, null);
            log.info("请求小恒钱包接口返回结果：" + result);
            JSONObject jsStr = JSONObject.parseObject(result);
            map.put("code", jsStr.getString("code"));
            map.put("error", jsStr.getString("error"));
            if (jsStr.containsKey("data")) {
//                if ("0".equals(jsStr.getString("code"))) {
//                    //返回结果code为1，表示请求成功
//                    String token = jsStr.getJSONObject("data").getString("token");
//                    map.put("token", token);
//                }
                if (jsStr.getJSONObject("data").containsKey("token")) {
                    String token = jsStr.getJSONObject("data").getString("token");
                    map.put("token", token);
                }
                if (jsStr.getJSONObject("data").containsKey("h5Url")) {
                    String h5Url = jsStr.getJSONObject("data").getString("h5Url");
                    map.put("h5Url", h5Url);
                }
            }
        } catch (Exception e) {
            log.info("请求小恒钱包接口:" + " 返回信息:" + e);
            throw new CustomerException(CustomerCodes.BIGDATA_INTERFACE_ERROR, "请求小恒钱包接口异常");
        }
        return map;
    }


    @Override
    public CustomerExtendCreditPo getCreditInfo(String phone, String channelNo, String subSystemSign) {
        try {
            CustomerExtendCreditPo po = new CustomerExtendCreditPo();
            po.setChannelNo(channelNo);
            po.setPhone(phone);
            po.setSubSystemSign(subSystemSign);
            List<CustomerExtendCreditPo> list = customerExtendCreditMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查取cust_extend_credit报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public void insertCustExtendCredit(String systemSign, String subSystemSign, String channelNo, String preCustomerNo, String ext1, String ext2, String ext3, String phone) {
        try {
            CustomerExtendCreditPo po = new CustomerExtendCreditPo();
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setId(UUIDUtils.getUUID());
            po.setStatus(1);
            po.setChannelNo(channelNo);
            po.setPreCustomerNo(preCustomerNo);
            po.setExt1(ext1);
            po.setExt2(ext2);
            po.setExt3(ext3);
            po.setPhone(phone);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            customerExtendCreditMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入cust_extend_credit报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public CustomerManageInfoPo getCustomerManageInfo(String customerNo, String subSystemSign) {
        try {
            CustomerManageInfoPo po = new CustomerManageInfoPo();
            po.setCustomerNo(customerNo);
            po.setSubSystemSign(subSystemSign);
            List<CustomerManageInfoPo> list = customerManageInfoMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询cust_manage_info异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public void updateTokenByPre(String newPreCustomerNo, String subSystemSign, String oldPreCustomerNo) {
        try {
            Example example = new Example(CustOauthTokenPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("preCustomerNo", oldPreCustomerNo);
            criteria.andEqualTo("subSystemId", subSystemSign);
            CustOauthTokenPo po = new CustOauthTokenPo();
            po.setPreCustomerNo(newPreCustomerNo);
            po.setModifyTime(new Timestamp(System.currentTimeMillis()));
            oauthTokenMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_oauth_token异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updateChannelByPre(String newPreCustomerNo, String subSystemSign, String oldPreCustomerNo) {
        try {
            Example example = new Example(CustOauthChannelPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("preCustomerNo", oldPreCustomerNo);
            criteria.andEqualTo("channelId", subSystemSign);
            CustOauthChannelPo po = new CustOauthChannelPo();
            po.setPreCustomerNo(newPreCustomerNo);
            po.setModifyTime(new Timestamp(System.currentTimeMillis()));
            oauthChannelMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_oauth_channel异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updateCustPreInfo(String id, String phone) {
        try {
            PreCustomerInfoPo po = new PreCustomerInfoPo();
            po.setId(id);
            po.setContactInfo(phone);
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            preCustomerMapper.updateByPrimaryKeySelective(po);
        } catch (DataAccessException e) {
            log.info("更新cust_pre_info异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void insertCustPreInfo(String preCustomerNo, String contactInfo) {
        try {
            PreCustomerInfoPo po = new PreCustomerInfoPo();
            po.setId(UUIDUtils.getUUID());
            po.setPreCustomerNo(preCustomerNo);
            po.setContactInfo(contactInfo);
            po.setContactType(CustomerConstants.CONTACT_TYPE_MOBILE);
            po.setContactVerified(CustomerConstants.STATUS_CONTACT_VERIFIED);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            po.setCreateDate(new Date(System.currentTimeMillis()));
            preCustomerMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入cust_pre_info异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }


    @Override
    public void insertCompanyModifyFlow(UnifyModifyBusinessRo ro, String systemSign, String subSystemSign, String modifyMsg) {
        try {
            CompanyModifyFlowPo po = new CompanyModifyFlowPo();
            BeanUtils.copyProperties(ro, po);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setModifyMsg(modifyMsg);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            companyModifyFlowMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入company_modify_flow异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void insertCustOauthLoginFlow(String requestNo, String systemSign, String subSystemSign, String loginCode, String preCustomerNo, Integer status) {
        try {
            //重复授权流水不插入
            CustOauthLoginFlowPo tempPo = new CustOauthLoginFlowPo();
            tempPo.setPreCustomerNo(preCustomerNo);
            tempPo.setSubSystemSign(subSystemSign);
            tempPo.setStatus(status);
            tempPo.setLoginCode(loginCode);
            List<CustOauthLoginFlowPo> list = oauthLoginFlowMapper.select(tempPo);
            if (list == null || list.size() == 0) {
                CustOauthLoginFlowPo po = new CustOauthLoginFlowPo();
                po.setSystemSign(systemSign);
                po.setRequestNo(requestNo);
                po.setSubSystemSign(subSystemSign);
                po.setStatus(status);
                po.setPreCustomerNo(preCustomerNo);
                po.setLoginCode(loginCode);
                po.setCreateTime(new Timestamp(System.currentTimeMillis()));
                oauthLoginFlowMapper.insert(po);
            }
        } catch (DataAccessException e) {
            log.info("插入cust_oauth_login_flow报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void updateCustOauthLoginFlow(String systemSign, String subSystemSign, String loginCode, String preCustomerNo, Integer status) {
        try {
            Example example = new Example(CustOauthLoginFlowPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("loginCode", loginCode);
            criteria.andEqualTo("preCustomerNo", preCustomerNo);
            criteria.andEqualTo("subSystemSign", subSystemSign);
            CustOauthLoginFlowPo po = new CustOauthLoginFlowPo();
            po.setStatus(status);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            oauthLoginFlowMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_oauth_login_flow报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updateCustExtendById(String id, Integer status) {
        try {
            Example example = new Example(CustomerExtendPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id", id);
            CustomerExtendPo po = new CustomerExtendPo();
            po.setStatus(status);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            customerExtendMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_extend报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public CustInvitationCodePo getInvitationCode(String preCustomerNo, String systemSign, String subSystemSign) {
        try {
            CustInvitationCodePo po = new CustInvitationCodePo();
            po.setPreCustomerNo(preCustomerNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setStatus(1);
            List<CustInvitationCodePo> list = invitationCodeMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询cust_invitation_code报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public CustInvitationRelationPo getInvitationRelation(String preCustomerNo, String systemSign, String subSystemSign) {
        try {
            CustInvitationRelationPo po = new CustInvitationRelationPo();
            po.setInvitationPreNo(preCustomerNo);
            po.setStatus(1);
            po.setInvitationSubSystemSign(subSystemSign);
            List<CustInvitationRelationPo> list = invitationRelationMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查询cust_invitation_relation报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public String handleInvitationCode(BaseRequest<CustomerUnifyLoginRo> request, String preCustomerNo) {
        CustomerUnifyLoginRo ro = request.getBody();
        String invitationCode = ro.getInvitationCode();
        CustInvitationCodePo po = new CustInvitationCodePo();
        po.setInvitationCode(invitationCode);
        po.setStatus(1);
//            po.setSubSystemSign(request.getSubSystemSign());
        List<CustInvitationCodePo> list = invitationCodeMapper.select(po);
        if (list != null && list.size() > 0) {
            CustInvitationCodePo data = list.get(0);
            //插入关联关系
            CustInvitationRelationPo relationPo = new CustInvitationRelationPo();
            relationPo.setInvitationPhone(ro.getPhone());
            relationPo.setInvitationPreNo(preCustomerNo);
            relationPo.setStatus(1);
            relationPo.setInvitationSubSystemSign(request.getSubSystemSign());
            relationPo.setInvitationSystemSign(request.getSystemSign());
            relationPo.setPreCustomerNo(data.getPreCustomerNo());
            relationPo.setCreateTime(new Timestamp(System.currentTimeMillis()));
            relationPo.setInvitationCode(invitationCode);
            relationPo.setSubSystemSign(data.getSubSystemSign());
            relationPo.setSystemSign(data.getSystemSign());
            invitationRelationMapper.insert(relationPo);
            //生成邀请码
        }
        return null;
    }


    @Override
    public void insertInvitationCode(String preCustomerNo, String phone, String invitationCode, String systemSign, String subSystemSign) {
        try {
            CustInvitationCodePo po = new CustInvitationCodePo();
            po.setPreCustomerNo(preCustomerNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setInvitationCode(invitationCode);
            po.setPhone(phone);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            po.setStatus(1);
            invitationCodeMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入cust_invitation_code报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void updateInvitationCode(String preCustomerNo, String systemSign, String subSystemSign, Integer status, String remark) {
        try {
            Example example = new Example(CustInvitationCodePo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("preCustomerNo", preCustomerNo);
            criteria.andEqualTo("systemSign", systemSign);
            criteria.andEqualTo("subSystemSign", subSystemSign);
            criteria.andEqualTo("status", 1);
            CustInvitationCodePo po = new CustInvitationCodePo();
            po.setStatus(status);
            po.setRemark(remark);
            po.setModifyTime(new Timestamp(System.currentTimeMillis()));
            invitationCodeMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_invitation_code报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updateInvitationRelation(String preCustomerNo, String systemSign, String subSystemSign, Integer status, String remark) {
        try {
            Example example = new Example(CustInvitationRelationPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("invitationPreNo", preCustomerNo);
            criteria.andEqualTo("invitationSystemSign", systemSign);
            criteria.andEqualTo("invitationSubSystemSign", subSystemSign);
            criteria.andEqualTo("status", 1);
            CustInvitationRelationPo po = new CustInvitationRelationPo();
            po.setStatus(status);
            po.setRemark(remark);
            invitationRelationMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_invitation_relation报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void deleteCustIdInfoById(String id) {
        try {
            CustomerIdInfoPo po = new CustomerIdInfoPo();
            po.setId(id);
            customerIdInfoMapper.delete(po);
        } catch (DataAccessException e) {
            log.error("删除cust_id_info异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_DELETE);
        }
    }

    @Override
    public void deleteCustManageInfo(String customerNo, String subSystemSign) {
        try {
            CustomerManageInfoPo po = new CustomerManageInfoPo();
            po.setCustomerNo(customerNo);
            po.setSubSystemSign(subSystemSign);
            customerManageInfoMapper.delete(po);
        } catch (DataAccessException e) {
            log.error("删除cust_manage_info异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_DELETE);
        }
    }

    @Override
    public void updateChannelById(String id, Integer status, String remark) {
        try {
            Example example = new Example(CustOauthChannelPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id", id);
            CustOauthChannelPo po = new CustOauthChannelPo();
            po.setStatus(status);
            if (StringUtils.isNotBlank(remark)) {
                po.setRemark(remark);
            }
            po.setModifyTime(new Timestamp(System.currentTimeMillis()));
            oauthChannelMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_oauth_channel异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updateCustExtendByAuth(String preCustomerNo, String systemSign, String subSystemSign, Integer status) {
        try {
            Example example = new Example(CustomerExtendPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("preCustomerNo", preCustomerNo);
            criteria.andEqualTo("systemSign", systemSign);
            criteria.andEqualTo("subSystemSign", subSystemSign);
            criteria.andEqualTo("status", 6);
            CustomerExtendPo po = new CustomerExtendPo();
            po.setStatus(status);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            customerExtendMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_extend报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updateChannelByCancel(String preCustomerNo, String systemSign, String subSystemSign, Integer status, String remark) {
        try {
            Example example = new Example(CustOauthChannelPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("preCustomerNo", preCustomerNo);
            criteria.andEqualTo("systemId", systemSign);
            criteria.andEqualTo("channelId", subSystemSign);
            CustOauthChannelPo po = new CustOauthChannelPo();
            po.setStatus(status);
            if (StringUtils.isNotBlank(remark)) {
                po.setRemark(remark);
            }
            po.setModifyTime(new Timestamp(System.currentTimeMillis()));
            oauthChannelMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_oauth_channel异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public PreCustomerPasswdPo getPasswd(String phone, String preCustomerNo, String systemSign, String subSystemSign, Integer status) {
        try {
            PreCustomerPasswdPo po = new PreCustomerPasswdPo();
            if (StringUtils.isNotBlank(preCustomerNo)) {
                po.setPreCustomerNo(preCustomerNo);
            }
            po.setMobile(phone);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setLockState(status);
            List<PreCustomerPasswdPo> list = preCustomerPassMapper.select(po);
            return list.size() > 0 ? list.get(0) : null;
        } catch (DataAccessException e) {
            log.info("查取cust_pre_passwd报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_QUERY);
        }
    }

    @Override
    public void insertPasswd(String phone, String preCustomerNo, String systemSign, String subSystemSign, String passwd, Integer status) {
        try {
            PreCustomerPasswdPo po = new PreCustomerPasswdPo();
            po.setPreCustomerNo(preCustomerNo);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setMobile(phone);
            po.setPasswd(EncryptUtils.getYztSha1(passwd));
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            po.setLockState(status);
            preCustomerPassMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入cust_pre_passwd报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void updatePasswdById(Integer id, String password, String remark) {
        try {
            Example example = new Example(PreCustomerPasswdPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id", id);
            PreCustomerPasswdPo po = new PreCustomerPasswdPo();
            po.setRemark(remark);
            if (StringUtils.isNotBlank(password)) {
                po.setPasswd(EncryptUtils.getYztSha1(password));
            }
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            preCustomerPassMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_pre_passwd异常:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updatePasswdByCancel(String phone, String systemSign, String subSystemSign, Integer status, String remark) {
        try {
            Example example = new Example(PreCustomerPasswdPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("mobile", phone);
            criteria.andEqualTo("systemSign", systemSign);
            criteria.andEqualTo("subSystemSign", subSystemSign);
            criteria.andEqualTo("lockState", 1);
            PreCustomerPasswdPo po = new PreCustomerPasswdPo();
            po.setLockState(status);
            po.setRemark(remark);
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            preCustomerPassMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_pre_passwd报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void updatePasswdByModify(String phone, String newPhone, String newPreCustomerNo, String systemSign, String subSystemSign, String remark) {
        try {
            Example example = new Example(PreCustomerPasswdPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("mobile", phone);
            criteria.andEqualTo("systemSign", systemSign);
            criteria.andEqualTo("subSystemSign", subSystemSign);
            criteria.andEqualTo("lockState", 1);
            PreCustomerPasswdPo po = new PreCustomerPasswdPo();
            po.setMobile(newPhone);
            po.setPreCustomerNo(newPreCustomerNo);
            po.setRemark(remark);
            po.setUpdateTime(new Timestamp(System.currentTimeMillis()));
            preCustomerPassMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_pre_passwd报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }

    @Override
    public void insertCustSmsPwdFlow(String phone, String systemSign, String subSystemSign, String requestNo, Integer status, String errorMsg, String smsCode, String ip, Integer type) {
        try {
            UnifySmsPwdFlowPo po = new UnifySmsPwdFlowPo();
            po.setPhone(phone);
            po.setSystemSign(systemSign);
            po.setSubSystemSign(subSystemSign);
            po.setRequestNo(requestNo);
            po.setStatus(status);
            po.setErrorMsg(errorMsg);
            po.setSmsCode(smsCode);
            po.setIp(ip);
            po.setType(type);
            po.setCreateTime(new Timestamp(System.currentTimeMillis()));
            pwdFlowMapper.insert(po);
        } catch (DataAccessException e) {
            log.info("插入cust_sms_pwd_flow报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_INSERT);
        }
    }

    @Override
    public void updateCustSmsPwdFlow(Timestamp unlockTime, Integer id) {
        try {
            Example example = new Example(UnifySmsPwdFlowPo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("id", id);
            UnifySmsPwdFlowPo po = new UnifySmsPwdFlowPo();
            po.setUnlockTime(unlockTime);
            pwdFlowMapper.updateByExampleSelective(po, example);
        } catch (DataAccessException e) {
            log.info("更新cust_sms_pwd_flow报错:" + ClassUtils.getClassName() + "--" + ClassUtils.getMethodName() + "--" + e.getMessage());
            throw new CustomerException(CustomerCodes.DATABASE_ERROR_UPDATE);
        }
    }


}
